﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
namespace gamexpert.admin
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (User.Identity.IsAuthenticated && User.IsInRole("Administrator"))
            {
                Response.Redirect("~/admin/ControlPanel.aspx");
            }
        }


        protected void Login1_LoggedIn(object sender, EventArgs e)
        {
            Response.Redirect("~/admin/ControlPanel.aspx");

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            MembershipUser u = Membership.GetUser(Login1.UserName);
            bool admin = false;
            if (u != null)
            {
                string[] roles = Roles.GetRolesForUser(u.UserName);
                foreach (string r in roles)
                {
                    if (r == "Administrator")
                    {
                        admin = true;
                        break;
                    }

                }
            }
            e.Authenticated = admin;
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/Default.aspx");
        }
    }
}
